home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / emac16as.arc / Z100.ASM < prev   
Assembly Source File  |  1990-04-01  |  17KB  |  853 lines

  1. ;History:273,1
  2. ;Tue Mar 06 11:19:30 1990 add give_up_slice.
  3. ;Sun May 07 00:41:05 1989 Move mouse code from pick.asm to z100.asm
  4. ;Mon Jan 30 22:58:01 1989 change the parameters to set_screen_color.
  5. ;05-17-88 19:40:10 remove definition of scrwait, which is not needed any longer [kdb]
  6. ;05-11-88 07:53:56 add the swap_screen_flag.
  7. ;04-20-88 08:09:40 null terminate the key buffer.
  8. ;03-30-88 23:32:08 add fore_original, back_original.
  9. ;03-30-88 20:32:23 the key_buffer was only 12 characters long, two too short.  Make it 16.
  10. ;03-13-88 23:00:14 add store_debug.
  11.  
  12.     page    ,132
  13.  
  14. comment /
  15.  
  16.     Porting EMACS and Percival to MS-DOS computers other than the Z-100:
  17.  
  18. This entire file (Z-100.ASM) needs to be re-written, since it contains
  19. all the Z-100 dependencies.  The following conventions must be maintained:
  20.   1) Never leave this module with DF=1.
  21.   2) Never destroy ES.
  22.   3) Never MOV AX,DATA, always use the copy in the appropriate segment register.
  23.   4) Return NC if a routine succeeds, or fulfills its goals.
  24.  
  25. /
  26.     .xlist
  27.  
  28.     include    memory.def
  29.  
  30.  
  31. ;the only bios call is used by check_for_key
  32. bios_seg    segment at 40h
  33.     org    27*3
  34. bios_confunc    label    far
  35. bios_seg    ends
  36.  
  37.  
  38. data    segment    byte public
  39.  
  40.     public    max_screen_line
  41. max_screen_line    db    22    ;number of last text row on screen.
  42.  
  43.     public    num_screen_cols
  44. num_screen_cols    db    80
  45.         db    0        ;in case they access a word.
  46.  
  47.     public    computer_name, computer_name_len
  48. computer_name    db    'Z100'
  49. computer_name_len    equ    $-computer_name
  50.  
  51. fontptr        dd    6fh
  52.  
  53. ;the following font pointers point to a font containing the 96 printable
  54. ;  characters, with the exception of the first which also contains graphics.
  55. ;  The first font is numbered zero, and has all the Zedit funnies.  The
  56. ;  second  font uses the first_font, but does inverse video for the high bit
  57. ;  characters.  The third font and on use the normal control character font to
  58. ;  print controls.  The last font is the internal font, and is used to print
  59. ;  control chars, etc.
  60. first_font    dw    ?,?        ;fonts zero and one.
  61.  
  62. controls_ptr    label    word        ;font eight.
  63.     dw    controls,?
  64.  
  65. controls    label    byte
  66.     include    control.asm
  67.  
  68.  
  69.     public    scan_lines_per_char
  70. scan_lines_per_char    db    9    ;used to convert pixel position into character position.
  71.  
  72.  
  73. mouse_flag    db    ?
  74. mouse_buttons    db    ?
  75.  
  76.  
  77. shifted    equ    40h
  78. key_names    label    byte
  79.     db    ',','Comma',0
  80.     db    '(','LPar',0
  81.     db    ')','RPar',0
  82.     db    7fh,'Delete',0
  83.     db    0a3h+shifted,'D Chr',0
  84.     db    0a3h,'I Chr',0
  85.     db    0a4h+shifted,'Del Line',0
  86.     db    0a4h,'Ins Line',0
  87.     db    -1,'Timeout',0
  88.     db    -2,'Left Down',0        ;mouse button key names.
  89.     db    -3,'Right Down',0
  90.     db    -4,'Left Up',0
  91.     db    -5,'Right Up',0
  92.     db    -6,'Middle Down',0
  93.   if 0
  94.     db    -7,'Middle Up',0
  95.   endif
  96.     db    0
  97.  
  98. key_shifted    label    byte
  99.     db    08Dh,'Enter',0
  100.     db    095h,'Help',0
  101.     db    096h,'F0',0
  102.     db    097h,'F1',0
  103.     db    098h,'F2',0
  104.     db    099h,'F3',0
  105.     db    09Ah,'F4',0
  106.     db    09Bh,'F5',0
  107.     db    09Ch,'F6',0
  108.     db    09Dh,'F7',0
  109.     db    09Eh,'F8',0
  110.     db    09Fh,'F9',0
  111.     db    0A0h,'F10',0
  112.     db    0A1h,'F11',0
  113.     db    0A2h,'F12',0
  114.     db    0A5h,'Up Arrow',0
  115.     db    0A6h,'Down Arrow',0
  116.     db    0A7h,'Right Arrow',0
  117.     db    0A8h,'Left Arrow',0
  118.     db    0A9h,'Home',0
  119.     db    0AAh,'Break',0
  120.     db    0ADh,'KP-',0
  121.     db    0AEh,'KP.',0
  122.     db    0B0h,'KP0',0
  123.     db    0B1h,'KP1',0
  124.     db    0B2h,'KP2',0
  125.     db    0B3h,'KP3',0
  126.     db    0B4h,'KP4',0
  127.     db    0B5h,'KP5',0
  128.     db    0B6h,'KP6',0
  129.     db    0B7h,'KP7',0
  130.     db    0B8h,'KP8',0
  131.     db    0B9h,'KP9',0
  132.     db    0,'Unknown',0
  133.  
  134.  
  135. key_buffer    label    byte
  136.     db    16 dup(?)
  137.  
  138.  
  139.     extrn    inversing: word
  140.  
  141.     public    fore_original, back_original
  142. fore_original    db    7
  143. back_original    db    0
  144.  
  145. color_xlat    db    0, 1, 4, 5, 2, 3, 6, 7, 0, 1, 4, 5, 2, 3, 6, 7
  146.  
  147.     public    swap_screen_flag
  148. swap_screen_flag    dw    0
  149.  
  150. data    ends
  151.  
  152.  
  153. bios_seg    segment at 40h
  154.     org    9h
  155. bios_conout    label    far
  156. bios_seg    ends
  157.  
  158.  
  159. code    segment    byte public
  160.     assume    cs:code, ds:data, es:nothing
  161. ;all of the code in this segment is called with the above assumes.
  162.  
  163.  
  164. printchar:
  165.     call    bios_conout
  166.     ret
  167.  
  168.  
  169.     public    init_entry
  170. init_entry:
  171. ;called when entering.  May destroy any but seg-regs.
  172.     push    es
  173.     xor    ax,ax
  174.     mov    es,ax
  175.     mov    ax,es:3feh    ;the monitor segment
  176.     mov    word ptr fontptr+2,ax
  177.     les    si,fontptr
  178.     mov    ax,es:[si]
  179.     mov    first_font,ax
  180.     mov    bx,es:[si+2]
  181.     mov    first_font+2,bx
  182.     pop    es
  183.     mov    controls_ptr+2,ds
  184.     mov    al,'y'            ;disable key expansion
  185.     call    printesc
  186.     mov    al,'?'
  187.     call    printchar
  188.     mov    al,'y'
  189.     call    printesc
  190.     mov    al,'1'
  191.     call    printchar
  192.     mov    al,'x'
  193.     call    printesc
  194.     mov    al,'1'
  195.     call    printchar
  196.     mov    dx,0*256 + 49        ;try to put the cursor way down low.
  197.     call    position_cursor
  198.     push    ds            ;see if it got there.
  199.     xor    ax,ax
  200.     mov    ds,ax
  201.     mov    ds,ds:[3feh]
  202.     mov    al,ds:[292h]
  203.     pop    ds
  204.     cmp    al,49            ;go if it didn't
  205.     jne    init_entry_1
  206.     mov    max_screen_line,47    ;it did - remember the last scrollable line.
  207. init_entry_1:
  208.     ret
  209.  
  210.  
  211.     public    uninit_exit
  212. uninit_exit:
  213. ;called when exiting.  May destroy any but seg-regs.
  214.     call    restore_font
  215.     mov    al,'x'            ;enable key expansion
  216.     call    printesc
  217.     mov    al,'?'
  218.     call    printchar
  219.     mov    al,'y'            ;disable the 25th line.
  220.     call    printesc
  221.     mov    al,'1'
  222.     call    printchar
  223.     mov    dh,0            ;put the cursor on the last scrollable line.
  224.     mov    dl,max_screen_line
  225.     inc    dl
  226.     call    position_cursor
  227.     ret
  228.  
  229.  
  230. restore_font:
  231.     push    es
  232.     les    si,fontptr
  233.     mov    ax,first_font
  234.     mov    es:[si],ax
  235.     mov    ax,first_font+2
  236.     mov    es:[si+2],ax
  237.     pop    es
  238.     ret
  239.  
  240.  
  241.     public    read_ibm_cga
  242. read_ibm_cga:
  243.     xor    al,al
  244.     ret
  245.  
  246.  
  247.     public    store_ibm_cga
  248. store_ibm_cga:
  249.     ret
  250.  
  251.  
  252.  
  253. ;this routine should check for a break character.  Return cy if none,
  254. ;  nc if we should break.
  255.     public    check_breakchar
  256. check_breakchar:
  257.     push    ax
  258.     call    check_for_key
  259.     jz    check_breakchar_1
  260.     cmp    ax,7            ;^G?
  261.     jne    check_breakchar_1
  262.     call    get_key_value
  263.     clc
  264.     pop    ax
  265.     ret
  266. check_breakchar_1:
  267.     stc
  268.     pop    ax
  269.     ret
  270.  
  271.  
  272.     public    give_up_slice
  273. give_up_slice:
  274.     ret
  275.  
  276.  
  277.     public    check_for_key
  278. check_for_key:
  279. ;return zr if no key is waiting.
  280. ;return nz,ax=key if a key is waiting, but don't input the key yet.
  281.     push    bx        ; Save regs
  282.     push    di
  283.     push    si
  284.     push    dx
  285.     push    ax
  286.     mov    ah,4        ; get look function
  287.     call    bios_confunc     ; get copy of first char in queue, empty?
  288.     mov    bl,0        ; assume queue empty, was it ?
  289.     jc    check_for_key_1    ;    yes, skip
  290.     mov    bl,al        ;    no, save char
  291. check_for_key_1:
  292.     mov    al,0ffh        ; get -1
  293.     adc    al,0        ; set 'z' flag appropriately
  294.     pop    ax        ; recover ax
  295.     mov    al,bl        ; get char
  296.     pop    dx        ; restore regs
  297.     pop    si
  298.     pop    di
  299.     pop    bx
  300.     mov    ah,0
  301.     ret
  302.  
  303.  
  304.     public    get_key_value
  305. get_key_value:
  306.     mov    ah,7
  307.     int    21h
  308.     mov    ah,0
  309.     ret
  310.  
  311.  
  312.     public    decode_key
  313. decode_key:
  314. ;enter with al=key value.
  315. ;exit with si,cx -> the key's name in ASCII.
  316.     mov    di,offset key_buffer
  317.     mov    ah,al
  318.     mov    si,offset key_names
  319.     call    decode_search        ;search for the literal names.
  320.     jne    decode_key_1
  321.     mov    si,offset key_shifted    ;search for the unshifted versions.
  322.     call    decode_search
  323.     jne    decode_key_1
  324.     push    ax            ;save the key's value.
  325.     and    ah,not shifted        ;search for the shifted versions.
  326.     mov    si,offset key_shifted    ;search for the unshifted versions.
  327.     call    decode_search
  328.     pop    ax            ;restore the key's value.
  329.     jne    decode_key_5        ;prefix with "S-"
  330.     mov    al,ah
  331.     cmp    al,' '            ;control char?
  332.     jb    decode_key_3        ;yes.
  333.     stosb                ;no - just return the char.
  334.     jmp    decode_key_2
  335. decode_key_3:
  336.     mov    word ptr [di],'C' + '-'*256
  337.     add    di,2
  338.     add    al,'@'
  339.     cmp    al,'A'
  340.     jb    decode_key_4
  341.     cmp    al,'Z'
  342.     ja    decode_key_4
  343.     add    al,20h            ;convert to lower case.
  344. decode_key_4:
  345.     stosb
  346.     jmp    decode_key_2
  347. decode_key_5:
  348.     mov    word ptr [di],'S' + '-'*256
  349.     add    di,2
  350. decode_key_1:
  351.     lodsb                ;copy to the next null.
  352.     stosb
  353.     or    al,al
  354.     jne    decode_key_1
  355.     dec    di            ;don't include the null.
  356. decode_key_2:
  357.     xor    al,al            ;terminate with a null
  358.     stosb
  359.     mov    si,offset key_buffer
  360.     ret
  361.  
  362.  
  363. decode_search:
  364. ;enter with ah=key to search for, si->table.
  365. ;exit with al=key, nz if found, al=0, zr if not found.
  366.     lodsb
  367.     or    al,al            ;end of table?
  368.     je    decode_search_2        ;yes - try shifted values.
  369.     cmp    al,ah            ;is this the key?
  370.     je    decode_search_2        ;yes.
  371. decode_search_1:
  372.     lodsb                ;skip to the next null.
  373.     or    al,al
  374.     jne    decode_search_1
  375.     jmp    decode_search
  376. decode_search_2:
  377.     or    al,al
  378.     ret
  379.  
  380. printesc:
  381. ;print an escape followed by the char in al.
  382.     push    ax
  383.     mov    al,'['-40h
  384.     call    printchar
  385.     pop    ax
  386.     call    printchar
  387.     ret
  388.  
  389.  
  390.     public    store_debug
  391. store_debug:
  392.     ret    ;regrettably, the Z-100 screen isn't fast enough for this.
  393.  
  394.  
  395.     public    ring_the_bell
  396. ring_the_bell:
  397.     mov    al,'G'-40h
  398.     call    printchar
  399.     ret
  400.  
  401. code    ends
  402.  
  403. code    segment    byte public
  404.     assume    cs:code, ds:nothing, es:data
  405. ;all of the code in this segment is called with the above assumes.
  406.  
  407.     public    position_cursor
  408. position_cursor:
  409. ;enter with dh=col (0...num_screen_cols), dl=row (0..max_screen_line)
  410. ;exit with cursor set to that position.
  411.     mov    al,'Y'
  412.     call    printesc
  413.     mov    al,dl
  414.     add    al,' '
  415.     call    printchar
  416.     mov    al,dh
  417.     add    al,' '
  418.     call    printchar
  419.     ret
  420.  
  421.  
  422.     public    solid_cursor
  423. solid_cursor:
  424.     mov    al,'x'
  425.     call    printesc
  426.     mov    al,';'
  427.     call    printchar
  428.     ret
  429.  
  430.  
  431.     public    blink_cursor
  432. blink_cursor:
  433.     mov    al,'y'
  434.     call    printesc
  435.     mov    al,';'
  436.     call    printchar
  437.     ret
  438.  
  439.  
  440.     public    block_cursor
  441. block_cursor:
  442.     mov    al,'x'
  443.     call    printesc
  444.     mov    al,'4'
  445.     call    printchar
  446.     ret
  447.  
  448.     public    underscore_cursor
  449. underscore_cursor:
  450.     mov    al,'y'
  451.     call    printesc
  452.     mov    al,'4'
  453.     call    printchar
  454.     ret
  455.  
  456.  
  457.     public    set_screen_color
  458. set_screen_color:
  459. ;enter with si -> color list.  Ignore control color and whitespace color.
  460.     mov    al,'m'
  461.     call    printesc
  462.     mov    bx,offset color_xlat
  463.     lodsb
  464.     xlat                ;translate from the stupid ibm scheme.
  465.     add    al,'0'            ;print the fore color number.
  466.     call    printchar
  467.     lodsb                ;print the back color number.
  468.     xlat
  469.     add    al,'0'
  470.     call    printchar
  471.     ret
  472.  
  473.  
  474.     public    move_line
  475. move_line:
  476. ;enter with dl=source row, al=destination row.
  477.     push    ax
  478.     push    bx
  479.     push    cx
  480.     push    dx
  481.     push    si
  482.     push    di
  483.     push    bp
  484.     push    es
  485.     push    ds
  486. ;start pushing mtr_mdl parameters
  487.     push    dx            ;source line.
  488.     push    ax            ;destination line.
  489.     xor    ax,ax
  490.     mov    ds,ax
  491.     mov    ds,ds:3feh        ;the monitor segment
  492.     call    dword ptr ds:[77h]    ;mtr_mdl
  493.     pop    ds
  494.     pop    es
  495.     pop    bp
  496.     pop    di
  497.     pop    si
  498.     pop    dx
  499.     pop    cx
  500.     pop    bx
  501.     pop    ax
  502.     ret
  503.  
  504.  
  505.     public    clear_to_eol
  506. clear_to_eol:
  507. ;enter with dl=current row, dh=current column.
  508.     push    bx
  509.     mov    bl,num_screen_cols
  510.     call    clear_count
  511.     pop    bx
  512.     ret
  513.  
  514.  
  515.     public    clear_count
  516. clear_count:
  517. ;enter with dl=current row, dh=current column, bl=column to clear to.
  518.     cmp    dh,bl        ;already past it?
  519.     jae    clear_count_1    ;yes.
  520.     push    ax
  521.     push    bx
  522.     push    cx
  523.     push    dx
  524.     push    si
  525.     push    di
  526.     push    bp
  527.     push    es
  528.     push    ds
  529. ;start pushing edc parameters.
  530.     push    dx            ;push row,
  531.     xchg    dl,dh
  532.     push    dx            ;push col.
  533.     sub    bl,dl
  534.     push    bx            ;push count of columns to clear.
  535.     xor    ax,ax
  536.     mov    ds,ax
  537.     mov    ds,ds:3feh        ;the monitor segment
  538.     call    dword ptr ds:[67h]    ;mtr_edl
  539.     pop    ds
  540.     pop    es
  541.     pop    bp
  542.     pop    di
  543.     pop    si            ;restore saved registers.
  544.     pop    dx
  545.     pop    cx
  546.     pop    bx
  547.     pop    ax
  548. clear_count_1:
  549.     ret
  550.  
  551.  
  552.     public    xychrout
  553. xychrout:
  554. ;enter with dh=col, dl=row, al=character to print, ah=font to print it in.
  555.     push    ax            ;save everything that we might need.
  556.     push    bx
  557.     push    cx
  558.     push    dx
  559.     push    di
  560.     push    si
  561.     push    es
  562.     push    ds
  563.     cmp    dh,num_screen_cols    ;past the right margin?
  564.     jae    xychrout_3        ;yes - don't print.
  565.     mov    si,offset first_font
  566.     cmp    ah,0            ;font zero?
  567.     jne    xychrout_5        ;no - print specially.
  568.     mov    bx,0            ;assume no inverse video
  569.     cmp    al,80h-'^'+7fh
  570.     jb    xychrout_1        ;print all normal chars normally.
  571.     jmp    short xychrout_0
  572. xychrout_5:
  573.     mov    si,offset controls_ptr
  574.     xor    bx,bx            ;assume no inverse video.
  575.     or    al,al            ;high bit set?
  576.     jns    xychrout_1        ;no - no inverse video.
  577. xychrout_0:
  578.     not    bx
  579.     and    al,7fh
  580. xychrout_1:
  581.     xor    bx,inversing        ;set the inverse video flag.
  582.     cmp    al,' '            ;print controls specially.
  583.     jb    xychrout_2
  584.     cmp    al,7fh            ;print delete specially.
  585.     je    xychrout_4
  586.     sub    al,' '
  587.     jmp    short xychrout_6
  588. xychrout_4:
  589.     sub    al,7fh-2fh        ;convert del to proper index in control font.
  590. xychrout_2:
  591.     mov    si,offset controls_ptr
  592. xychrout_6:
  593.     mov    cx,es            ;ensure that ds:si ->font pointer.
  594.     mov    ds,cx
  595.     les    di,fontptr
  596.     movsw
  597.     movsw
  598.     push    ds
  599. ;push four words as parameters to mtr_dfc
  600.     xchg    dh,dl
  601.     push    dx            ;push col first
  602.     xchg    dh,dl
  603.     push    dx            ;push row next.
  604.     push    ax            ;push font index.
  605.     push    bx            ;push inverse video flag.
  606.     xor    ax,ax
  607.     mov    ds,ax
  608.     mov    ds,ds:3feh        ;the monitor segment
  609.     call    dword ptr ds:[5fh]    ;mtr_dfc
  610.     pop    ds
  611.     call    restore_font
  612. xychrout_3:
  613.     pop    ds
  614.     pop    es
  615.     pop    si
  616.     pop    di
  617.     pop    dx
  618.     pop    cx
  619.     pop    bx
  620.     pop    ax
  621.     ret
  622.  
  623.  
  624.     public    hardware_roll_down
  625. hardware_roll_down:
  626. ;exit: if this machine is capable of hardware roll, do it and exit with cy=0,
  627. ;  otherwise, exit with cy=1.  The hardware roll must leave the last line
  628. ;  on the screen as the last line.
  629. ;preserve bx.
  630.     cmp    ah,0
  631.     jnz    no_hardware_roll
  632.     cmp    al,max_screen_line
  633.     jnz    no_hardware_roll
  634.     push    dx
  635.     mov    al,max_screen_line    ;move the lower status line up.
  636.     mov    dl,al
  637.     inc    dl
  638.     call    move_line        ;dl=source, al=dest.
  639.     pop    dx
  640.     mov    al,'H'            ;home up.
  641.     call    printesc
  642.     mov    al,'I'            ;reverse index.
  643.     call    printesc
  644.     clc
  645.     ret
  646. no_hardware_roll:
  647.     stc
  648.     ret
  649.  
  650.  
  651.     public    hardware_roll_up
  652. hardware_roll_up:
  653. ;exit: if this machine is capable of hardware roll, do it and exit with cy=0,
  654. ;  otherwise, exit with cy=1.  The hardware roll must leave the last line
  655. ;  on the screen as the last line.
  656. ;preserve bx.
  657.     cmp    ah,0
  658.     jnz    no_hardware_roll
  659.     cmp    al,max_screen_line
  660.     jnz    no_hardware_roll
  661.     push    dx
  662.     mov    dl,max_screen_line
  663.     inc    dl
  664.     mov    dh,0
  665.     call    position_cursor
  666.     mov    al,LF            ;roll the screen up.
  667.     call    printchar
  668.     mov    al,max_screen_line    ;move the lower status line up.
  669.     mov    dl,al
  670.     dec    dl
  671.     call    move_line        ;dl=source, al=dest.
  672.     pop    dx
  673.     clc
  674.     ret
  675.  
  676.  
  677.     public    pick_init, pick_on, pick_off, check_pick, get_pick_values
  678. pick_init:
  679.     call    mouse_exists
  680.     mov    ax,0
  681.     int    33h
  682.     mov    mouse_flag,al        ;remember if the mouse exists.
  683.     mov    mouse_buttons,bl    ;remember the number of buttons.
  684.     mov    ax,4            ;move the mouse to the upper right hand.
  685.     mov    cx,635
  686.     mov    dx,0
  687.     int    33h
  688.     mov    ax,10            ;set text cursor (ignored on Z-100).
  689.     mov    bx,0            ;software text cursor.
  690.     mov    cx,77ffh        ;screen mask
  691.     mov    dx,7700h        ;cursor mask
  692.     int    33h
  693.  
  694.     mov    al,max_screen_line    ;compute the "number of scan lines"
  695.     add    al,2
  696.     mul    scan_lines_per_char
  697.     dec    dx
  698.     mov    dx,ax            ;set the "number of scan lines"
  699.     mov    cx,0
  700.     mov    ax,8
  701.     int    33h
  702.  
  703.     mov    al,8            ;we're assuming nine bits per char.
  704.     mul    num_screen_cols
  705.     dec    ax
  706.     mov    dx,ax            ;set the "number of bit columns"
  707.     mov    cx,0
  708.     mov    ax,7
  709.     int    33h
  710.  
  711.     call    check_pick        ;ensure that there are no up or down
  712.     call    check_pick        ;  events left.
  713.     call    check_pick
  714.     call    check_pick
  715.     call    check_pick
  716.     call    check_pick
  717.     ret
  718.  
  719.  
  720. pick_on:
  721.     call    mouse_exists
  722.     mov    ax,1
  723.     int    33h
  724.     ret
  725.  
  726.  
  727. pick_off:
  728.     call    mouse_exists
  729.     mov    ax,1            ;ensure that we work with MOUSEKEY.
  730.     int    33h
  731.     mov    ax,2
  732.     int    33h
  733.     ret
  734.  
  735.  
  736. check_pick:
  737. ;return nz and al=pick character.  return zr if no pick.
  738.     call    mouse_exists
  739.     push    bx
  740.     push    cx
  741.     push    dx
  742.     cmp    mouse_flag,0        ;inhibit mouse presses if it isn't there.
  743.     je    check_pick_1
  744.     mov    ax,5
  745.     mov    bx,0            ;left button press
  746.     int    33h
  747.     mov    ax,0feh
  748.     or    bx,bx
  749.     jne    check_pick_1
  750.     mov    ax,5            ;right button press
  751.     mov    bx,1
  752.     int    33h
  753.     mov    ax,0fdh
  754.     or    bx,bx
  755.     jne    check_pick_1
  756.     mov    ax,6            ;left button release
  757.     mov    bx,0
  758.     int    33h
  759.     mov    ax,0fch
  760.     or    bx,bx
  761.     jne    check_pick_1
  762.     mov    ax,6            ;right button release
  763.     mov    bx,1
  764.     int    33h
  765.     mov    ax,0fbh
  766.     or    bx,bx
  767.     jne    check_pick_1
  768.     cmp    mouse_buttons,2        ;do we have only two buttons?
  769.     je    check_pick_1        ;yes - no pick.
  770.     mov    ax,6            ;middle button release
  771.     mov    bx,2
  772.     int    33h
  773.     mov    ax,0f9h
  774.     or    bx,bx
  775.     jne    check_pick_1
  776.     mov    ax,5            ;middle button press
  777.     mov    bx,2
  778.     int    33h
  779.     mov    ax,0fah
  780.     or    bx,bx
  781.     jne    check_pick_1
  782. check_pick_1:
  783.     pop    dx
  784.     pop    cx
  785.     pop    bx
  786.     ret
  787.  
  788. get_pick_values:
  789.     mov    cx,0
  790.     mov    dx,0
  791.     call    mouse_exists
  792.     mov    ax,3
  793.     int    33h
  794.  
  795.     push    cx            ;save the x value.
  796.  
  797.     mov    ax,dx
  798.     div    scan_lines_per_char
  799.     mov    ah,0
  800.     push    ax
  801.     call    read_linesbefore
  802.     push    ax
  803.     call    read_newrow
  804.     pop    bx
  805.     sub    bx,ax            ;bx=linesbefore - newrow.
  806.     pop    dx
  807.     add    dx,bx            ;add y-value.
  808.     inc    dx            ;ax= y-value - newrow + linesbefore + 1.
  809.     pop    ax            ;compute the x-value.
  810.  
  811.     push    dx
  812.  
  813.     mov    cl,8
  814.     div    cl
  815.     mov    ah,0
  816.     inc    ax
  817.     push    ax            ;add in firstcolumn.
  818.     call    read_firstcolumn
  819.     pop    cx
  820.     add    cx,ax
  821.  
  822.     pop    dx
  823.  
  824.     ret
  825.  
  826.     extrn    read_firstcolumn: near
  827.     extrn    read_linesbefore: near
  828.     extrn    read_newrow: near
  829.  
  830.  
  831. ;this routine returns from the routine that called it if the mouse is not
  832. ;  installed.
  833. mouse_exists:
  834.     push    ds
  835.     xor    ax,ax
  836.     mov    ds,ax
  837.     mov    ax,word ptr ds:[33h*4+2]
  838.     pop    ds
  839.     cmp    ax,0            ;any mouse interrupt at all?
  840.     je    mouse_exists_2        ;no - no mouse.
  841.     cmp    ax,40h            ;is the mouse interrupt in the bios?
  842.     jne    mouse_exists_1        ;no - must be a real mouse.
  843. mouse_exists_2:
  844.     add    sp,2
  845.     xor    ax,ax
  846.     ret
  847. mouse_exists_1:
  848.     ret
  849.  
  850. code    ends
  851.  
  852.     end
  853.